<?php

class Admin_Model_Locationrent{

	private $locationRentTbl;
	
	public function __construct(){
		$this->locationRentTbl = new Admin_Model_DbTable_Locationrent();
	}
	
	public function selectLoactionRent($where=null,$order='khuVuc',$limit=NULL){
		$dbAdapter = Zend_Db_Table::getDefaultAdapter();
		$dbSelect = new Zend_Db_Select($dbAdapter);
		
		$dbSelect->from(array('kv'=>'khuvucthue'),'*');
		
		if ($where!=NULL) {
			$dbSelect->where($where);
		}
		$dbSelect->order($order);
		
		if ($limit!=null) {
			$dbSelect->limit($limit);
		}
		
		return $dbSelect;
	}
	
	public function fetchAllLocationRent($where=NULL){
		if($where !=NULL){
			return 	$this->locationRentTbl->fetchAll($where);
		}else {
			return $this->locationRentTbl->fetchAll();
		}
	}
	
	public function addLocation($khuVuc,$trong=0){
		$data = array(
			'khuVuc'	=> $khuVuc,
			'trong'		=> $trong
		);
		$this->locationRentTbl->insert($data);
	}
	
	public function  addCustomLocation($data){
		$this->locationRentTbl->insert($data);
	}
	
	public function updateLocation($khuVuc,$trong=0,$khuVucId){
		$data = array(
			'khuVuc' => $khuVuc,
			'trong'	=> $trong,
		);
		$this->locationRentTbl->update($data, 'khuVucId ='.$khuVucId);
	}
	
	public function updateCustomLocation($data,$where){
		$this->locationRentTbl->update($data, $where);
	}
	
	public function deleteLocation($khuVucId){
		$this->locationRentTbl->delete('khuVucId ='.$khuVucId);
	}

}

